
#ifndef __SOCK_INET_HXX__
#define __SOCK_INET_HXX__

////////////////////////////////////////////////////////////////////////////////

#include <sys/socket.h>
#include <stdint.h>
#include <string>

////////////////////////////////////////////////////////////////////////////////

class sock_inet
{
public:
    class address
    {
    public:
        address(uint32_t host, uint16_t service);
        address(const std::string& host, const std::string& service);

        bool operator==(const address& lhs) const;
        operator std::string() const;

        uint32_t get_host() const;
        uint16_t get_service() const;
        const sockaddr& get_sockaddr() const;
        sockaddr& get_sockaddr();

    protected:
        sockaddr addr;
    };

    class timeout
    {
    public:
        timeout(int64_t usec);
        int64_t get_usec() const;

    protected:
        int64_t usec;
    };

    sock_inet(sock_inet&&);
    ~sock_inet();

    address get_local() const;
    int get_fd() const;

    void shutdown();
    bool wait(const timeout& t);

protected:
    sock_inet(int sfd);
    sock_inet(int type, int protocol);

    void bind(const address& a);

    int sfd;
};

////////////////////////////////////////////////////////////////////////////////

#endif
